# Stage 1   
FROM node:lts-slim as build-step

WORKDIR /app

RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml ./
# COPY package-lock.json ./
# npm-script 'prepare' need to handle some code, so copy before install dependencies
COPY . .
RUN pnpm install --force && pnpm build

# Stage 2
FROM node:lts-slim
WORKDIR /src
COPY --from=build-step /app ./
# COPY --from=build-step package-lock.json ./
RUN npm install -g pnpm
RUN pnpm install --prod

# COPY --from=build-step /app/.next ./
# we copy source files as orm need them, it also fix the path of relative static files
# COPY src ./src

EXPOSE 3000

# Run server
CMD ["pnpm", "start"]